package com.mentalhealthplatform.studentV3.service;

import com.aliyun.oss.OSS;
import com.aliyun.oss.model.ListObjectsRequest;
import com.aliyun.oss.model.OSSObjectSummary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Pear
 */
@Service
public class VideoServiceV3 {

    @Autowired
    private OSS ossClient;

    @Value("${aliyun.oss.bucketName}")
    private String bucketName;

    public List<String> listAllVideos() {
        ListObjectsRequest listObjectsRequest = new ListObjectsRequest(bucketName);
        // 获取存储桶中的所有对象
        List<OSSObjectSummary> objectSummaries = ossClient.listObjects(listObjectsRequest).getObjectSummaries();

        // 只返回文件名，过滤出以 ".mp4" 结尾的对象
        return objectSummaries.stream()
                .map(OSSObjectSummary::getKey)
                .filter(key -> key.endsWith(".mp4"))
                .collect(Collectors.toList());
    }
}
